package com.alan;

import com.alan.mogo.entity.User;
import com.alan.mogo.service.UserService;
import com.loser.core.wrapper.LambdaQueryWrapper;
import com.loser.core.wrapper.Wrappers;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.List;
import java.util.Queue;

@SpringBootConfiguration
@SpringBootApplication
public class MongoStarterApplication {

    public static void main(String[] args) {

        ConfigurableApplicationContext context = SpringApplication.run(MongoStarterApplication.class, args);
        UserService userService = context.getBean(UserService.class);

        long id = 112;
        User user = new User();
        user.setId(id);
        user.setLoginName("loser");
        user.setPassWord("loser");
        user.setAge(18);
        user.setCreateTime(System.currentTimeMillis());
        user.setUpdateTime(System.currentTimeMillis());

        // 测试保存
        boolean save = userService.save(user);
        System.out.println("save = " + save);

        // 测试主键查询
        User dbUser = userService.getById(id);
        System.out.println("dbUser = " + dbUser);

        // 测试更新
        dbUser.setAge(19);
        LambdaQueryWrapper<User> updateQuery = Wrappers.<User>lambdaQuery().eq(User::getId, id);
        boolean update = userService.update(dbUser, updateQuery);
        System.out.println("update = " + update);

        // 测试条件查询
        LambdaQueryWrapper<User> query = Wrappers.<User>lambdaQuery().select(User::getAge, User::getLoginName)
                .eq(User::getLoginName, "loser").eq(User::getPassWord, "loser").skip(0L).limit(1);
        List<User> list = userService.list(query);
        System.out.println("list = " + list);

    }

}
